//
//  PCDApiShowToast.m
//  PCDMPaasBank
//
//  Created by DK on 2021/3/8.
//  Copyright © 2021 Alibaba. All rights reserved.
//

#import "PCDApiShowToast.h"
#import "UIView+Toast.h"

@implementation PCDApiShowToast

- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback
{
      
    NSString *title = [data objectForKey:@"title"];
    NSString *icon = [data objectForKey:@"icon"];
    CGFloat duration = 1.5;
    if ([data objectForKey:@"duration"]) {
        duration = [[data objectForKey:@"duration"] integerValue]/1000;
    }
//    BOOL mask = [data objectForKey:@"mask"];
    NSString *callBack = [data objectForKey:@"success"];
    
    if ([icon isEqualToString:@"success"]) {
        icon = @"toast_success";
    }
	else if ([icon isEqualToString:@"fail"]) {
		icon = @"toast_failure";
	}
	else if ([icon isEqualToString:@"loading"]) {
        icon = @"toast_loading";
    } else {
        icon = @"";
    }
    
    UIImage *toastImage = [UIImage imageNamed:icon];
    if ([PCDUIUtil nilOrEmptyString:icon]) {
        toastImage = nil;
    }
    
    UIViewController *viewPage =    context.viewController;
//	[PCDToastView showWithView:viewPage.view withText:title withImage:toastImage withImageSize:(PCDToastViewImageSizeDefault) withImagePosition:(PCDToastViewImagePositionTop) withDelay:1 withPosition:(PCDToastViewPostionCenter)];
    CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
	style.imageSize = CGSizeMake(40, 40);
    [viewPage.view makeToast:title duration:duration position:CSToastPositionCenter title:nil image:toastImage style:style completion:^(BOOL didTap) {
    }];
    
    if (![PCDUtil nilOrEmptyString:callBack]) {
        evaluateJavaScriptOnMainThread_quotes(self,callBack,@"");
    }
}

@end
